package net.lab1024.smartadmin.module.weapp.orderstype.controller;

import net.lab1024.smartadmin.common.domain.PageResultDTO;
import net.lab1024.smartadmin.common.controller.BaseController;
import net.lab1024.smartadmin.common.domain.ResponseDTO;
import net.lab1024.smartadmin.common.domain.ValidateList;
import net.lab1024.smartadmin.module.weapp.orderstype.domain.dto.WorkOrderTypeAddDTO;
import net.lab1024.smartadmin.module.weapp.orderstype.domain.dto.WorkOrderTypeUpdateDTO;
import net.lab1024.smartadmin.module.weapp.orderstype.domain.dto.WorkOrderTypeQueryDTO;
import net.lab1024.smartadmin.module.weapp.orderstype.domain.vo.WorkOrderTypeVO;
import net.lab1024.smartadmin.module.weapp.orderstype.domain.vo.WorkOrderTypeExcelVO;
import net.lab1024.smartadmin.module.weapp.orderstype.service.WorkOrderTypeService;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import org.apache.poi.ss.usermodel.Workbook;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * [ 工单类型 ]
 *
 * @author wuqian
 * @version 1.0
 * @company 五千
 * @copyright (c)  五千Inc. All rights reserved.
 * @date 2021-03-12 09:13:38
 * @since JDK1.8
 */
@RestController
@Api(tags = {"工单类型"})
public class WorkOrderTypeController extends BaseController {

    @Autowired
    private WorkOrderTypeService workOrderTypeService;

    @ApiOperation(value = "分页查询工单类型",notes = "@author wuqian")
    @PostMapping("/workOrderType/page/query")
    public ResponseDTO<PageResultDTO<WorkOrderTypeVO>> queryByPage(@RequestBody WorkOrderTypeQueryDTO queryDTO) {
        return workOrderTypeService.queryByPage(queryDTO);
    }

    @ApiOperation(value = "添加工单类型",notes = "@author wuqian")
    @PostMapping("/workOrderType/add")
    public ResponseDTO<String> add(@RequestBody @Validated WorkOrderTypeAddDTO addTO){
        return workOrderTypeService.add(addTO);
    }

    @ApiOperation(value="修改工单类型",notes = "@author wuqian")
    @PostMapping("/workOrderType/update")
    public ResponseDTO<String> update(@RequestBody @Validated WorkOrderTypeUpdateDTO updateDTO){
        return workOrderTypeService.update(updateDTO);
    }

    @ApiOperation(value="批量删除工单类型",notes = "@author wuqian")
    @PostMapping("/workOrderType/deleteByIds")
    public ResponseDTO<String> delete(@RequestBody @Validated ValidateList<Long> idList) {
        return workOrderTypeService.deleteByIds(idList);
    }

    @ApiOperation(value = "批量导出", notes = "@author wuqian")
    @PostMapping("/workOrderType/export/batch")
    public void batchExport(@RequestBody @Validated ValidateList<Long> idList, HttpServletResponse response) {
        //查询数据
        List<WorkOrderTypeExcelVO> workOrderTypeList = workOrderTypeService.queryBatchExportData(idList);
        //导出操作
        ExportParams ex = new ExportParams("工单类型", "Sheet1");
        Workbook workbook = ExcelExportUtil.exportExcel(ex, WorkOrderTypeExcelVO.class, workOrderTypeList);
        downloadExcel("工单类型", workbook, response);
    }

    @ApiOperation(value = "导出全部", notes = "@author wuqian")
    @PostMapping("/workOrderType/export/all")
    public void exportAll(@RequestBody @Validated WorkOrderTypeQueryDTO queryDTO, HttpServletResponse response) {
        //查询数据
        List<WorkOrderTypeExcelVO> workOrderTypeList = workOrderTypeService.queryAllExportData(queryDTO);
        //导出操作
        ExportParams ex = new ExportParams("工单类型", "Sheet1");
        Workbook workbook = ExcelExportUtil.exportExcel(ex, WorkOrderTypeExcelVO.class, workOrderTypeList);
        downloadExcel("工单类型", workbook, response);
    }

}
